Create Assessment Form from csv (Assetic Python SDK)
Introduction
The Assetic Python SDK allows a new Assessment form to be created using a csv file to define the form.
There are 2 aspects to the form creation:
-
Defining the fields in the form via a csv file.
-
Setting basic form attributes such as form name, description, form level etc. This step has been simplified by a script that prompts you for the required information. See the Quick Start below.
Refer also to the article Manage Custom Assessment Forms for additional information about assessment forms and how they are created using the Assetic application itself.
Quick Start
NOTE Make sure your Assetic Python SDK version is 2017.13.1.0 or greater. Refer to the article Assetic Python SDK Quick Start for details on how to install or upgrade the Assetic Python SDK.
First create a csv file (using Excel or other editor) or Download this sample here: (FormFields.csv)
Contains parent/child comboxbox (FormFieldsParentChild.csv)
(Samples may open in the browser rather than downloading. Right-click in the browser and choose the 'Save As' option)
Data Sample:
The following csv data sample shows a typical structure for creating an assessment form. It is shown in a grid to make each column more obvious.
The column structure of this csv data is Label, Type, Attributes, Widget, Required, Hint
| Operating Facility | 100 | Facility Detail | True | The facility name | |
| Primary Location | 100 | Facility Detail | True | Main Location | |
| System | Dropdown | 1|Type A;2|Type B | System Detail | True | |
| Classification | System Detail | ||||
| Installed Area | NumericStepper | 0|100|1|n0 | System Detail | ||
| Complexity of Access | Dropdown | Low|Low;Medium|Medium;High|High | Facility Detail | ||
| Comment | MultiLineText | 1000 | System Detail | As per standard AC:3423 | |
| Is Active | Checkbox | Facility Detail | |||
| Tagged Service Date | Date | System Detail | |||
| Running Since | DateTime | System Detail | The date and time the unit was last started | ||
| Location | Map | Facility Detail |
Some notes about the above sample:
-
Only 1 column is mandatory, the "Label" column. All other columns are optional, and the order of the columns is not fixed.
-
'Facility Detail' and 'System Detail' are the labels for the 2 control groups that will contain the form fields. The form will therefore need to be created with a layout containing at least 2 control groups
-
Where the form field "Type" column is empty, the default will be TextBox.
-
Default values are applied if the "Attributes" cell is empty
-
The format of the contents of the "Attributes" cell varies depending on the form field type
-
The default value for 'Required' is False (i.e. the field is not mandatory)
Form Creation
Having created the csv file, the next step is to create the form.
Hint: You may need to right click and 'Save As' (Assetic.AssessmentFormCreateByPrompt.py)
This script will prompt you for the form details and create the form. Once the form is created you will be prompted to launch Assetic. Assetic will launch and display the new form in the Assessments Admin module.
Defining Parent-Child Combobox Relationships
A parent-child combobox relationship can be defined such that the selection of a value in the parent combobox results in the filtering of child combobox values.
To define these relationships 2 additional columns are added to the csv file. The columns are only populated for the child combobox definition row in the the csv:
-
ParentLabel
-
The 'label' of the parent combox to associate the child combobx to
-
-
ParentRelation
-
This is the relationship of the child combobox values to the parent comboxbox values and is by its nature complex to define.
-
The definition requires each child combobox value to be linked to values from the parent combobox.
-
A pair of carets ^^ to delimit each child combobox link setting
-
Within each child combobox link setting the parent combobox values are delimited by a semicolon. A pipe is used to delimit the child combobox value from the subsequent list of parent combobox values
-
-
The following example from the sample file FormFieldsParentChild.csv illustrates the configuration.
| Label | Type | Attributes | ParentRelation | ParentLabel |
| System | Dropdown | 1|Type A;2|Type B;3|All | ||
| Sub System | Dropdown | 1|Sub A1;2|Sub A2;3|Sub B1;4|Sub B2 | 1|1;3^^2|1;3^^3|2;3^^4|2;3 | System |
Based on the above configuration the following outcome is expected:
| Parent Selection | Child Selection Options |
| Type A | Sub A1, Sub A2 |
| Type B | Sub B1, Sub B2 |
| All | Sub A1, Sub A2, Sub B1, Sub B2 |
Advanced Options and Field Descriptions
The Assetic Python SDK supports form creation without having to use the script AssessmentFormCreateByPrompt.py. The following sections describe in detail the structure of the field types and how to create a form without using the script from the Quick Start section above.
1. Form Attributes
The python object assetic.AssessmentFormCreateRepresentation is used to define the form attributes required by the Assessments API.
The following attributes of an assessment form can be set via this representation:
|
Attribute Name |
Description | Mandatory | Default |
| form_name | The name of the form to create. Must be unique. This will not be user visible, but this is the reference name used when using the Assetic Data Exchange API for bulk importing Assessment Form Results (Data Exchange Integration) | Yes | - |
| form_label | A user friendly label for the form that is shown when selecting the form in Data Exchange and advanced search | Yes | - |
| form_level | Defines the module that the from targets. One of: "Asset", "GroupAsset", "ComplexAsset","Component", "ComponentServiceCriteria","NetworkEntity","SimpleAsset", "WorkOrder", "WorkRequest", "WorkTask","AssesmentsResult", "Documents", "AsmtProject", "AsmtTask", "ServiceCriteria" | Yes | - |
| version | A version number to assign to the form | No | 1 |
| can_add_attachment | Allows document attachments to be linked to the form. Boolean True/False | No | True |
| tab_label | The label of the tab in the form | No | "Tab" |
| layout_pattern | Defines the pattern of the form layout. Options include but not limited to: "Single", "column: 2 equal columns" | No | "Single" |
| widget_labels |
For the given layout, each group of controls has a label. This is an array. "Single" has 1 group of controls, "column: 2 equal columns" has 2 groups of controls so 2 labels are required |
No | "Data" |
| label_formatter | Use a custom method to reformat the label as it appears in the csv file. Examples include replacing "_" with " ", or converting upper case to 'proper case' so that the labels are more user friendly. Useful where an external application is generating the csv file. | No | - |
2. Form Labels - CSV file structure
A csv file is used to define the list of fields in a form.
NOTE this file should not have a 'header' row that defines each column. The column structure is defined when executing the form creation.
The structure of the csv file follows a basic pattern whereby each row in the csv file represents a control in the form. A "control" is the fields in a form that data will be added to.
At a minimum the 'label' (user-visible label) of the control is required. The control type will default to 'TextBox' if only a list of labels is provided.
The controls available are:
| Type | Description | Data Attributes | Default Data Settings |
| TextBox | Standard single line text box | Character limit | 200 character limit |
| MultiLineText | Text that may span multiple lines. Use where there is a large amount of text | Character limit | 1000 character limit |
| Dropdown | A dropdown list of items. Can set values with user friendly descriptions | Dropdown items, values with corresponding labels | - |
| Date | A datetime field that allows date to be selected by a calendar popup | - | - |
| DateTime | A datetime field that allows date to be selected by a calendar popup and time to be selected by a time dropdown | - | - |
| NumericStepper |
A numeric field with arrows to increase or decrease the number. The minimum value, maximum value, and value to increment the number by via the stepper may also be defined |
Minimum value, Maximum value, Step value, number format |
min=0, max=100, step=1, format=n0 |
| CheckBox | A True/False style tick box | - | - |
| Map | A map window | - | - |
A column in the csv file that uses the same control type names as above can be used to set the control type for each label. It is permissible to use control names that vary from the above - refer to 'Non-standard control type names' below.
The following attributes for a control may be defined:
| Attribute Type | Description | Format | Default |
| Attributes | The data attributes of the control as defined in the table above per control type. This is a single column in the csv file that used for all the different control types. The format will therefore change per control type. |
For Dropdown separate the value from the label with "|", and separate each pair of items with ";". Optionally use a separate column for dropdown items (format is unchanged) For Numeric stepper separate min value, max value, step increment, and number format with "|". Optionally use up to 4 separate columns in the file purely for stepper attributes ('minval", "maxval", "increment", "valueformat") For text and multiline text define an integer value for field length. Optionally use a separate column in the file purely for 'Length' |
As above |
| Hint | A 'mouse-over' hint (tooltip) to apply to the control. | Text | No hint if undefined |
| Required | Indicates the field is mandatory, and when viewing the form an asterisk will appear beside the label | True/False | False |
| Name | The reference name for the control. Use this if integrating to another system and the name is required for integration | Text. Cannot start with a number and should not have hyphens within the name. Must be unique within the form | A unique id will be generated for the name |
| Widget | The name of the form group widget to place the control in. Required if a layout with more than one form group widget has been defined. | Text. Must match the name of one of the widgets from the form definition "widget_labels" | - |
3. Non-standard control type names
If another system has created the csv file, and the control type names vary from the above list, the control type name used in the csv file can be matched to one of the examples above using the "control_types" dictionary property of the SDK AssessmentHelper module.
assesshelp = assetic.AssessmentHelper(asseticsdk.client) assesshelp.control_types["MultiLineText"] = "Multi line Text" assesshelp.control_types["NumericStepper"] = "Numeric"
Code Sample
The following code sample is a complete sample for creating an assessment form from a csv file. It uses the same csv data as in the sample above, except the names for the types "MultiLineText" and "NumericStepper" are different in the csv file (to illustrate how this is managed)
